//
//  Url.swift
//  YOKO
//
//  Created by 鲁浩 on 16/5/19.
//  Copyright © 2016年 15Tec. All rights reserved.
//

import Foundation


//test: "https://test1.yokolife.com"
//server: "https://server.yokolife.com"
//let URL_BASE = "https://test1.yokolife.com"
let URL_BASE = "https://server.yokolife.com"

// Login
let URL_TOKEN: String = revert("/sso/token")
let URL_FEED_BACK: String = revert("/feedback/web")
let URL_REQUEST_SMS_CODE = revert("/sms/sms/registercode/send")
let URL_REQUEST_SMS_TOKEN = revert("/app/sms/token")
let URL_UPLOAD_REG_ID = revert("/regId")

// Sync
var URL_SYNC_ADD_CALENDAR: String {
    return revertWithToken("/app/calendar")
}
//var URL_SYNC_ADD_EVENT: String {
//    return revertWithTokenAndId("/app/event/", id: NSUserDefaults.getCurrentCalendarId())
//}
func URL_SYNC_ADD_EVENT(id: String) -> String {
    return revertWithTokenAndId("/app/event/", id: id)
}
var URL_SYNC_UPDATE_CALENDAR: String {
    return revertWithToken("/app/calendar/update")
}
//var URL_SYNC_UPDATE_EVENT: String {
//    return revertWithTokenAndId("/app/event/", id: NSUserDefaults.getCurrentCalendarId())
//}
func URL_SYNC_UPDATE_EVENT() -> String {
    return revertWithToken("/app/event")
}
var URL_SYNC_PULL: String {
    return attachSyncToken(revertWithToken("/app/calendar/list"))
}
var URL_SYNC_APP_UPDATE: String {
    return revert("/app/version/check")
}

let ACCESS_TOKEN = "access_token"
let SYNC_TOKEN = "syncToken"

func revert(path: String) -> String {
	return URL_BASE + path
}

func revertWithToken(path: String) -> String {
    return URL_BASE + path + "?access_token=" + NSUserDefaults.getAccessToken()!
}

func revertWithTokenAndId(path: String, id: String) -> String {
    return URL_BASE + path + id + "?access_token=" + NSUserDefaults.getAccessToken()!
}



func attachSyncToken(path: String) -> String {
    if ((NSUserDefaults.getSyncToken()) != nil) {
        return path + "&sync_token" + NSUserDefaults.getSyncToken()!
    } else {
        return path
    }
}